package com.wlxk.core.tool;

import java.util.Collection;
import java.util.Map;

/**
 * @author PanQiangQiang
 * @since 2021-10-28 13:15:11
 */
public class WlEmptyUtil {

    public static boolean isEmpty(Object o) {
        if (null == o) {
            return true;
        } else if (o instanceof CharSequence) {
            return isBlank((CharSequence) o);
        } else if (o instanceof Collection) {
            return ((Collection) o).isEmpty();
        } else if (o instanceof Map) {
            return ((Map) o).isEmpty();
        } else if (o instanceof Object[]) {
            Object[] object = (Object[]) o;
            if (object.length == 0) {
                return true;
            }
            for (int i = 0; i < object.length; i++) {
                if (isNotEmpty(object[i])) {
                    return false;
                }
            }
            return true;
        }
        return false;
    }

    public static boolean isNotEmpty(Object o) {
        return !isEmpty(o);
    }

    public static boolean isNotBlank(CharSequence cs) {
        return !isBlank(cs);
    }

    public static boolean isBlank(CharSequence cs) {
        int strLen;
        if (cs != null && (strLen = cs.length()) != 0) {
            for (int i = 0; i < strLen; ++i) {
                if (!Character.isWhitespace(cs.charAt(i))) {
                    return false;
                }
            }
            return true;
        } else {
            return true;
        }
    }
}
